{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "29c8525b",
   "metadata": {},
   "source": [
    "# 1.列表的私有方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "52a1a52e",
   "metadata": {},
   "source": [
    "## 1.1 增加 append().  insert()."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "f6cf812e",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\", \"Mary\", \"Jan\", \"Jack\"]\n",
    "stu_id = [10001,10002,10003,10004,10005,10008,10009,10001]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c913f4c3",
   "metadata": {},
   "source": [
    "### 1.增加append()，增加在最后一位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ad781781",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'Mary', 'Jan', 'Jack', 'Alex']\n"
     ]
    }
   ],
   "source": [
    "names.append(\"Alex\")\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2d86305b",
   "metadata": {},
   "source": [
    "### 2.插入insert(), 插入列表中指定位置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "93e9bb8d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'xiaoma', 'Mary', 'Jan', 'Jack', 'Alex']\n"
     ]
    }
   ],
   "source": [
    "names.insert(1,\"xiaoma\")\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "67cc5d72",
   "metadata": {},
   "source": [
    "### 列表中可以放重复出现的值，如果要放唯一值，列表不是最优选"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f2d2d49b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'xiaoma', 'xiaoma', 'Mary', 'Jan', 'Jack', 'Alex']\n"
     ]
    }
   ],
   "source": [
    "names.insert(2,\"xiaoma\")\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3fc88f6e",
   "metadata": {},
   "source": [
    "## 1.2 删除 remove().  pop()."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6d380ab9",
   "metadata": {},
   "source": [
    "### 1.remove().一般情况下，使用remove先用in判断"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f5b4e2d5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'Mary', 'Jan', 'Jack', 'Alex']\n"
     ]
    }
   ],
   "source": [
    "print(names)\n",
    "if \"xiaoma\" in names:\n",
    "    names.remove(\"xiaoma\")\n",
    "    print(names)\n",
    "    # remove只删除列表重复出现的第一个"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "27c7063b",
   "metadata": {},
   "source": [
    "### 2.pop().删除位置为1的这个元素"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "0bf806c9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pop方法后的names： ['Mike', 'Jan', 'Jack', 'Alex']\n"
     ]
    }
   ],
   "source": [
    "names.pop(1)\n",
    "print(\"pop方法后的names：\",names)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "269f4c8a",
   "metadata": {},
   "source": [
    "### 3.index().索引, 查看该元素如Mike在names中第一个出现的位置的索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "0e13fc95",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n"
     ]
    }
   ],
   "source": [
    "print(names.index(\"Mike\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "008033f3",
   "metadata": {},
   "source": [
    "### 4.clear().清除所有的数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "3ec66681",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "clear清除后的值 []\n"
     ]
    }
   ],
   "source": [
    "names.clear()\n",
    "print(\"clear清除后的值\",names)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57c33014",
   "metadata": {},
   "source": [
    "### 5.count().查看列表元素出现的个数,（简单应用）统计分数出现的次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "7c6ee625",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "count方法后的结果 2\n"
     ]
    }
   ],
   "source": [
    "print(\"count方法后的结果\",stu_id.count(10001))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b89ae460",
   "metadata": {},
   "source": [
    "### 6.extend()是给指定的list进行扩充"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "3941df83",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'Mary', 'Jan', 'Jack', 10001, 10002, 10003, 10004, 10005, 10008, 10009, 10001]\n"
     ]
    }
   ],
   "source": [
    "names.extend(stu_id)\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "48d25440",
   "metadata": {},
   "source": [
    "# 2.列表的其他方法（Suquence Types 的一些方法）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "adff1233",
   "metadata": {},
   "source": [
    "## 2.1len() 查看列表长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "671e484b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "names的长度： 0\n"
     ]
    }
   ],
   "source": [
    "print(\"names的长度：\",len(names))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c943b679",
   "metadata": {},
   "source": [
    "## 2.2 in判断元素是否在列表里面"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "e072472c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "print(\"Jan\" in names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f70f8e0b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
